home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 445_01 / pi5ways / pi3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-05  |  1.4 KB  |  42 lines

  1. /**************************************************************************/
  2. /*              Calculate π by Leonhard Euler approximation               */
  3. /*   π ≈ √ { 6 ( 1/1 + 1/4 + 1/9 + 1/16 + 1/25 ... + 1/(n+1)**2 ...) }    */
  4. /*                                                                        */
  5. /*                                                                        */
  6. /*                                M\Cooper                                */
  7. /*                       3425 Chestnut Ridge Rd.                          */
  8. /*                        Grantsville, MD 21536                           */
  9. /*                       -------------------------                        */
  10. /*                       email: thegrendel@aol.com                        */   
  11. /*                                   06/91                                */
  12. /*                   Source code placed in the public domain              */                 
  13. /**************************************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <math.h>
  17.  
  18. #define MAX 5000
  19.  
  20. void main()
  21. {
  22.    double intermediate_result = 0,
  23.           Pi;
  24.    register int k;
  25.  
  26.  
  27.  
  28.  
  29.       for( k = 0; k <= MAX; k++ )
  30.         {  
  31.         intermediate_result += 1.0 / ( ( k + 1.0 ) * ( k + 1.0 ) );
  32.         Pi = sqrt( 6.0 * intermediate_result );
  33.  
  34.         printf( "Term #%5d  ------->  π ≈ %f  \n", k, Pi ); 
  35.         }
  36.  
  37. }
  38.  
  39.  
  40.  
  41.  
  42.